﻿using DocumentFormat.OpenXml.Packaging;
using Microsoft.SharePoint;

namespace SP.Exporters.Extractors
{
    /// <summary>
    /// A default implementation of the IFieldValueExtractorFactory interface
    /// </summary>
    public class DefaultWordFieldValueExtractorFactory : IFieldValueExtractorFactory
    {
        public MainDocumentPart MainDocumentPart { get; set; }

        /// <summary>
        /// Creates the replacer. 
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="format">The format.</param>
        /// <returns></returns>
        public IFieldValueExtractor CreateReplacer(SPField field, string format)
        {
            switch (field.Type)
            {
                case SPFieldType.DateTime:
                    return new FieldDateTimeExtractor(field, format);
                case SPFieldType.URL:
                    return new FieldUrlExtractor(field, MainDocumentPart);
                default:
                    return new FieldStandardExtractor(field);
            }
        }
    }
}
